/**
 * @description 基础控制类
 * @since 2019-11-12
 * @author Rid King
*/

const ox = require('@daelui/oxjs')

class Controller extends ox.Controller {
  beforeRenderTpl (_, options) {
    // 查询所有的文档数据
    return this.$router.getControllInstance({path: '/dblog/note'}).queryTypes().then(res => {
      let noteTypes = res.data
      options.data = options.data || {}
      options.data.noteTypes = Array.isArray(noteTypes) ? noteTypes : []
    }).then(() => {
      return this.$router.getControllInstance({path: '/dblog/links'}).queryAll({}, {
        action: {},
        params: {
          status: 1
        },
        excute: {
          operators: [
            {field: 'status', operator: 'EQUAL'}
          ],
          sort: [
            {field: 'createTime', by: 'desc'},
            {field: 'orders', by: 'desc'}
          ]
        }
      }).then(res => {
        let links = res.data
        options.data = options.data || {}
        options.data.links = Array.isArray(links) ? links : []
      })
    })
  }
}

module.exports = Controller